1
2
3
4
5
6
7
8
9
10
11
12
13
14 package com.google.common.collect;
15
16 import com.google.common.annotations.GwtCompatible;
17
18 import java.util.NoSuchElementException;
19 import java.util.Set;
20
21 import javax.annotation.Nullable;
22
23
24
25
26
27
28 @GwtCompatible(emulated = true)
29 @SuppressWarnings("unchecked")
30 final class EmptyContiguousSet<C extends Comparable> extends ContiguousSet<C> {
31 EmptyContiguousSet(DiscreteDomain<C> domain) {
32 super(domain);
33 }
34
35 @Override public C first() {
36 throw new NoSuchElementException();
37 }
38
39 @Override public C last() {
40 throw new NoSuchElementException();
41 }
42
43 @Override public int size() {
44 return 0;
45 }
46
47 @Override public ContiguousSet<C> intersection(ContiguousSet<C> other) {
48 return this;
49 }
50
51 @Override public Range<C> range() {
52 throw new NoSuchElementException();
53 }
54
55 @Override public Range<C> range(BoundType lowerBoundType, BoundType upperBoundType) {
56 throw new NoSuchElementException();
57 }
58
59 @Override ContiguousSet<C> headSetImpl(C toElement, boolean inclusive) {
60 return this;
61 }
62
63 @Override ContiguousSet<C> subSetImpl(
64 C fromElement, boolean fromInclusive, C toElement, boolean toInclusive) {
65 return this;
66 }
67
68 @Override ContiguousSet<C> tailSetImpl(C fromElement, boolean fromInclusive) {
69 return this;
70 }
71
72 @Override public UnmodifiableIterator<C> iterator() {
73 return Iterators.emptyIterator();
74 }
75
76 @Override boolean isPartialView() {
77 return false;
78 }
79
80 @Override public boolean isEmpty() {
81 return true;
82 }
83
84 @Override public ImmutableList<C> asList() {
85 return ImmutableList.of();
86 }
87
88 @Override public String toString() {
89 return "[]";
90 }
91
92 @Override public boolean equals(@Nullable Object object) {
93 if (object instanceof Set) {
94 Set<?> that = (Set<?>) object;
95 return that.isEmpty();
96 }
97 return false;
98 }
99
100 @Override public int hashCode() {
101 return 0;
102 }
103 }
104